package com.example.headlines.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.headlines.MainActivity;
import com.example.headlines.R;
import com.example.headlines.activity.NewsActivity;
import com.example.headlines.activity.RegisterActivity;
import com.example.headlines.adapter.VideoAdapter;
import com.example.headlines.adapter.VideoAdapter2;
import com.example.headlines.entity.VideoEntity;
import com.example.headlines.entity.VideoEntity2;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link VideoFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class VideoFragment2 extends BaseFragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String title;
    private List<String> contents;
    private List<String> contents2;

    public VideoFragment2() {
    }

    public static VideoFragment2 newInstance(String title,List<String> contents) {
        VideoFragment2 fragment = new VideoFragment2();
        fragment.title = title;
        fragment.contents=contents;
//        fragment.contents2=contents2;
        return fragment;

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.fragment_video, container, false);
        RecyclerView recyclerView=v.findViewById(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        Log.i("list", contents.toString());
//        v.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//             showToast("我被点击了");
//            }
//        });

        List<VideoEntity2> datas = new ArrayList<>();
        for (int i = 0; i < contents.size(); i+=3) {
            VideoEntity2 ve = new VideoEntity2();
            ve.setTitle(contents.get(i+1));
//            ve.setName("大胃王");
            ve.setContent(contents.get(i));
            ve.setDzCount(i * 2);
            ve.setCollectCount(i * 4);
            ve.setCommentCount(i * 6);
            datas.add(ve);
        }
        VideoAdapter2 videoAdapter = new VideoAdapter2(getActivity(), datas);
        recyclerView.setAdapter(videoAdapter);
        videoAdapter.setOnItemClickListener(new VideoAdapter2.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(getActivity(), NewsActivity.class);
                intent.putExtra("title", contents.get(position*3+1));
                intent.putExtra("content", contents.get(position*3));
                intent.putExtra("img", contents.get(position*3+2));
                startActivity(intent);
            }
        });
        return v;

    }

    @Override
    protected int initLayout() {
        return 0;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }
}